﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cocos2d;
using Meteorite;
using Microsoft.Xna.Framework;
using System.Diagnostics;
using ChaseCameraSample;

using OpenXLive;
using OpenXLive.Forms;
using OpenXLive.Features;
using Microsoft.Xna.Framework.Input;

namespace Meteorite
{
    public class StatsticsScene : CCScene, ICCTargetedTouchDelegate
    {        
        public StatsticsScene()
        {
            CCSize size = CCDirector.sharedDirector().getWinSize();

            //Title
            CCPoint p = new CCPoint(GameConstant.Point_CenterTop.x, GameConstant.Point_CenterTop.y-40);
            CCLabelBMFont Title = CCLabelBMFont.labelWithString("Statstics", GameConstant.Font_Futura_48);
            addChild(Title);
            Title.position = p;
            Title.scale = 2.0f;

            const float scale = 0.8f;
            const float offset = -40;
            CCPoint AnchorPoint = new CCPoint(0, 0);
            //
            CCPoint p1 = new CCPoint(0+100, p.y + offset*3);
            int n1 = UserData.Instance().GetValue(GameConstant.UserData_TotalGamesPlayed);
            CCLabelBMFont t1 = CCLabelBMFont.labelWithString(GameConstant.UserData_TotalGamesPlayed, GameConstant.Font_Futura_48);
            t1.scale = scale;
            t1.position = p1;
            t1.anchorPoint = AnchorPoint;
            addChild(t1);

            CCPoint p1_ = new CCPoint(p1.x+300, p1.y);
            int n1_ = UserData.Instance().GetValue(GameConstant.UserData_TotalGamesPlayed);
            CCLabelBMFont t1_ = CCLabelBMFont.labelWithString(string.Format("{0,20}", n1.ToString()), GameConstant.Font_Futura_48);
            t1_.scale = scale;
            t1_.position = p1_;
            t1_.anchorPoint = AnchorPoint;
            addChild(t1_);

            CCPoint p2 = new CCPoint(p1.x, p1.y + offset);
            int n2 = UserData.Instance().GetValue(GameConstant.UserData_HighScore);
            CCLabelBMFont t2 = CCLabelBMFont.labelWithString(GameConstant.UserData_HighScore, GameConstant.Font_Futura_48);
            t2.scale = scale;
            t2.position = p2;
            t2.anchorPoint = AnchorPoint;
            addChild(t2);

            CCPoint p2_ = new CCPoint(p2.x+300, p2.y);
            int n2_ = UserData.Instance().GetValue(GameConstant.UserData_HighScore);
            CCLabelBMFont t2_ = CCLabelBMFont.labelWithString(string.Format("{0,20}", n2.ToString()), GameConstant.Font_Futura_48);
            t2_.scale = scale;
            t2_.position = p2_;
            t2_.anchorPoint = AnchorPoint;
            addChild(t2_);

            CCPoint p3 = new CCPoint(p2.x, p2.y + offset);
            int n3 = UserData.Instance().GetValue(GameConstant.UserData_TotalPlayTime);
            CCLabelBMFont t3 = CCLabelBMFont.labelWithString(GameConstant.UserData_TotalPlayTime, GameConstant.Font_Futura_48);
            t3.scale = scale;
            t3.position = p3;
            t3.anchorPoint = AnchorPoint;
            addChild(t3);

            CCPoint p3_ = new CCPoint(p2.x+300, p3.y);
            int n3_ = UserData.Instance().GetValue(GameConstant.UserData_TotalPlayTime);
            CCLabelBMFont t3_ = CCLabelBMFont.labelWithString(string.Format("{0,20}", TimeSpan.FromSeconds(n3).ToString()), GameConstant.Font_Futura_48);
            t3_.scale = scale;
            t3_.position = p3_;
            t3_.anchorPoint = AnchorPoint;
            addChild(t3_);

            CCPoint p4 = new CCPoint(p3.x, p3.y + offset);
            int n4 = UserData.Instance().GetValue(GameConstant.UserData_LastPlayTime);
            CCLabelBMFont t4 = CCLabelBMFont.labelWithString(GameConstant.UserData_LastPlayTime, GameConstant.Font_Futura_48);
            t4.scale = scale;
            t4.position = p4;
            t4.anchorPoint = AnchorPoint;
            addChild(t4);

            CCPoint p4_ = new CCPoint(p3.x+300, p3.y + offset);
            int n4_ = UserData.Instance().GetValue(GameConstant.UserData_LastPlayTime);
            string s4_ = string.Format("{0,20}", TimeSpan.FromSeconds(n4).ToString());
            CCLabelBMFont t4_ = CCLabelBMFont.labelWithString(s4_, GameConstant.Font_Futura_48);
            t4_.scale = scale;
            t4_.position = p4_;
            t4_.anchorPoint = AnchorPoint;
            addChild(t4_);

            CCPoint p5 = new CCPoint(p4.x, p4.y + offset);
            int n5 = UserData.Instance().GetValue(GameConstant.UserData_ColideStone);
            CCLabelBMFont t5 = CCLabelBMFont.labelWithString(GameConstant.UserData_ColideStone, GameConstant.Font_Futura_48);
            t5.scale = scale;
            t5.position = p5;
            t5.anchorPoint = AnchorPoint;
            addChild(t5);

            CCPoint p5_ = new CCPoint(p5.x+300, p5.y);
            int _n5 = UserData.Instance().GetValue(GameConstant.UserData_ColideStone);
            string s5_ = string.Format("{0,20}", n5);
            CCLabelBMFont t5_ = CCLabelBMFont.labelWithString(s5_, GameConstant.Font_Futura_48);
            t5_.scale = scale;
            t5_.position = p5_;
            t5_.anchorPoint = AnchorPoint;
            addChild(t5_);

            CCPoint p6 = new CCPoint(p5.x, p5.y + offset);
            int n6 = UserData.Instance().GetValue(GameConstant.UserData_TotalStone);
            CCLabelBMFont t6 = CCLabelBMFont.labelWithString(GameConstant.UserData_TotalStone, GameConstant.Font_Futura_48);
            t6.scale = scale;
            t6.position = p6;
            t6.anchorPoint = AnchorPoint;
            addChild(t6);

            CCPoint p6_ = new CCPoint(p6.x+300, p6.y);
            int n6_ = UserData.Instance().GetValue(GameConstant.UserData_TotalStone);
            string s6_ = string.Format("{0,20}", n6_);
            CCLabelBMFont t6_ = CCLabelBMFont.labelWithString(s6_, GameConstant.Font_Futura_48);
            t6_.scale = scale;
            t6_.position = p6_;
            t6_.anchorPoint = AnchorPoint;
            addChild(t6_);

            CCPoint p7 = new CCPoint(p6.x, p6.y + offset);
            int n7 = UserData.Instance().GetValue(GameConstant.UserData_TotalBounus);
            CCLabelBMFont t7 = CCLabelBMFont.labelWithString(GameConstant.UserData_TotalBounus, GameConstant.Font_Futura_48);
            t7.scale = scale;
            t7.position = p7;
            t7.anchorPoint = AnchorPoint;
            addChild(t7);

            CCPoint p7_ = new CCPoint(p7.x+300, p7.y);
            int n7_ = UserData.Instance().GetValue(GameConstant.UserData_TotalBounus);
            string s7_ = string.Format("{0,20}",n7_);
            CCLabelBMFont t7_ = CCLabelBMFont.labelWithString(s7_, GameConstant.Font_Futura_48);
            t7_.scale = scale;
            t7_.position = p7_;
            t7_.anchorPoint = AnchorPoint;
            addChild(t7_);
            //MenuGetIn();

        }
        public override void onEnter()
        {
            CCTouchDispatcher.sharedDispatcher().addTargetedDelegate(this, 0, true);
            base.onEnter();
        }

        public override void onExit()
        {
            CCTouchDispatcher.sharedDispatcher().removeDelegate(this);
            base.onExit();
        }
        public virtual void ccTouchEnded(CCTouch touch, CCEvent eventer)
        {
            
        }
        public virtual bool ccTouchBegan(CCTouch touch, CCEvent eventer)
        {
            /* bug
            if (CCDirector.sharedDirector().runningScene is StatsticsScene)
            {
                CCDirector.sharedDirector().popScene();
            }
             * */
            return true;
        }

        public virtual void ccTouchMoved(CCTouch touch, CCEvent eventer)
        {
        
        }

        public void ccTouchCancelled(CCTouch pTouch, CCEvent pEvent)
        {
        }
        private void MenuGetIn()
        {
            /*
            CCSize size = CCDirector.sharedDirector().getWinSize();
            Title.runAction(CCMoveTo.actionWithDuration(0.8f, new CCPoint(size.width / 2, size.height - 100)));

            Score.runAction(CCMoveTo.actionWithDuration(0.5f, new CCPoint(size.width / 2, size.height - 250)));

            ButtonPlayAgain.runAction(CCMoveTo.actionWithDuration(0.6f, new CCPoint(size.width / 2, size.height - 300)));
            ButtonMenu.runAction(CCMoveTo.actionWithDuration(0.7f, new CCPoint(size.width / 2, size.height - 350)));
             * */

        }
        private void MenuGetOut()
        {
            /*
            CCSize size = CCDirector.sharedDirector().getWinSize();
            Title.runAction(CCMoveTo.actionWithDuration(0.8f, new CCPoint(size.width / 2, size.height + 60)));

            Score.runAction(CCMoveTo.actionWithDuration(0.8f, new CCPoint(size.width / 2, -size.height)));

            ButtonPlayAgain.runAction(CCMoveTo.actionWithDuration(0.5f, new CCPoint(size.width / 2, -size.height)));
            ButtonMenu.runAction(CCMoveTo.actionWithDuration(0.2f, new CCPoint(size.width / 2, -size.height)));
             * */
        }
    }
}
